/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-05-30 10:56:05
 * @LastEditTime : 2023-06-07 08:58:20
 * @LastEditors  : NaN 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\FirstLevel\Material.jsx
 * @Description  :
 */

import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton } from '../Common/options'
import { MaterialTypeTree } from '../Common/Conversion'

const independenceList = {
    'jtgj.ljkjkf.com': 'organizationUuid',
}

const orgStatus = ['jtgj.ljkjkf.com']

export const Material = async ({ url, OptionsEvent, ClientData, Permission }) => {
    const { hostname } = window.location

    Permission = Permission?.find(v => v.targetUrl === url).children
    const parentUuid = await MaterialTypeTree()
    let data = {
        pageSize: 10,
        independenceSet: {
            title: '组织机构',
            url: 'getOrgTree',
            data: { IsByUserUuid: 1 },
            type: 'TableNavTree001',
            all: true,
        },
        independence: independenceList[hostname],
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission?.findIndex(v => v.uuid === '4ba571c1-54ff-4646-96c1-7a47479e1df1') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增材料信息" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            {
                ...commonTableList.organizationUuid,
                valueEnum: ClientData.organization,
                hideInAdded: orgStatus.includes(hostname),
                hideInModify: orgStatus.includes(hostname),
                hideInSearch: orgStatus.includes(hostname),
                hideInTable: orgStatus.includes(hostname),
            },
            {
                dataIndex: 'materialTypeUuid',
                title: '材料类别',
                valueType: 'treeSelect',
                fieldProps: {
                    options: parentUuid,
                    fieldNames: { label: 'tableName', value: 'uuid' },
                },
                rules: true,
                hideInSearch: true,
                width: 150,
            },
            { ...commonTableList.tableName, title: '材料名称' },
            {
                dataIndex: 'spec',
                title: '材料规格',
                valueType: 'input',
                width: 150,
                hideInSearch: true,
            },
            {
                dataIndex: 'unit',
                title: '单位',
                valueType: 'input',
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'warnNum',
                title: '库存预警数量',
                valueType: 'inputNumber',
                width: 100,
                hideInSearch: true,
            },
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === 'f698629d-cc6e-4a93-a6a6-38e15cce16cb') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '1ee21caa-7b52-48dc-a385-f12cf9144d22') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
